jQuery(document).ready(function () {
    EgiComBase.init();
});

var EgiComBase = function () {
    
    var initDaterange=function() {
        if (!jQuery().daterangepicker) {
            return;
        }
    
        $('.egidaterangepicker').daterangepicker({
            "ranges": {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
                '一周内': [moment().subtract('days', 6), moment()],
                '一个月内': [moment().subtract('days', 29), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
            },
            "locale": {
                "format": "YYYY/MM/DD",
                "separator": " - ",
                "applyLabel": "应用",
                "cancelLabel": "取消",
                "fromLabel": "从",
                "toLabel": "至",
                "customRangeLabel": "自定义",
                "daysOfWeek": [
                    "周日",
                    "周一",
                    "周二",
                    "周三",
                    "周四",
                    "周五",
                    "周六"
                ],
                "monthNames": [
                    "一月",
                    "二月",
                    "三月",
                    "四月",
                    "五月",
                    "六月",
                    "七月",
                    "八月",
                    "九月",
                    "十月",
                    "十一月",
                    "十二月"
                ],
                "firstDay": 1
            },
            //"startDate": "11/08/2015",
            //"endDate": "11/14/2015",
            opens: (App.isRTL() ? 'right' : 'left'),
        }, function(start, end, label) {
            $('.egidaterangepicker span').html(start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD'));
        });
    
        $('.egidaterangepicker span').html(moment().subtract('days', 29).format('YYYY/MM/DD') + ' - ' + moment().format('YYYY/MM/DD'));
        $('.egidaterangepicker').show();
    };

    /*
    *函数功能：从href获得参数
    *sHref:   http://www.artfh.com/arg.htm?arg1=d&arg2=re
    *sArgName:arg1, arg2
    *return:    the value of arg. d, re
    */
   function GetArgsFromHref(sHref, sArgName)
   {
       var args    = sHref.split("?");
       var retval = "";
       
       if(args[0] == sHref) /*参数为空*/
       {
           return retval; /*无需做任何处理*/
       }  
       var str = args[1];
       args = str.split("&");
       for(var i = 0; i < args.length; i ++)
       {
           str = args[i];
           var arg = str.split("=");
           if(arg.length <= 1) continue;
           if(arg[0] == sArgName) retval = arg[1]; 
       }
       return retval;
   }    

    return {
        init: function () {
            //事件绑定
            initDaterange();
        },
        GetArgsFromHref: function (sHref, sArgName) {
            //事件绑定
            return GetArgsFromHref(sHref, sArgName);
        }
    };
}();

